package doyouknow.group.CnAndZhb.controller;

import doyouknow.group.CnAndZhb.entity.TbcPoint;
import doyouknow.group.CnAndZhb.error.BusinessException;
import doyouknow.group.CnAndZhb.error.EnumBusinessError;
import doyouknow.group.CnAndZhb.response.BaseControllerReturn;
import doyouknow.group.CnAndZhb.service.TbcPointService;
import doyouknow.group.CnAndZhb.utils.SerializedField;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbcPoint)表控制层
 *
 * @author makejava
 * @since 2020-12-08 18:20:25
 */
@RestController
@RequestMapping("tbcPoint")
public class TbcPointController extends BaseController{
    /**
     * 服务对象
     */
    @Resource
    private TbcPointService tbcPointService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @SerializedField(includes = {"deviceMac"})
    public TbcPoint selectOne(Integer id) {
        return this.tbcPointService.queryById(id);
    }

    @GetMapping("queryPoints")
    @SerializedField(includes = {"deviceMac","network","pointNumber","monitorValue","readtag","updatetime"})
    public Object queryByMac(String gatewayMac) throws BusinessException {

        if (StringUtils.isEmpty(gatewayMac)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_VALIDATION_ERROR,"请输入正确的设备号");
        }

        List<TbcPoint> tbcPointList =  tbcPointService.queryPoints(gatewayMac);
        return BaseControllerReturn.create(tbcPointList,null);
    }

}